package org.oschina.api.manage.menu.service;

import java.util.List;

import org.oschina.Module;
import org.oschina.api.BaseService;
import org.oschina.api.manage.menu.dao.ManageMenuDAO;
import org.oschina.api.manage.menu.vo.ManageMenuVo;
import org.oschina.api.user.user.model.User;
import org.oschina.api.user.user.service.UserService;
import org.oschina.security.annotation.Require;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ManageMenuService extends BaseService {

	@Autowired
	private ManageMenuDAO manageMenuDAO;
	@Autowired
	private UserService userService;

	/**
	 * 根据角色返回
	 * @return
	 */
	@Require(authorization=Module.MODULE_3)
	public List<ManageMenuVo> findVoByRole()
	{
		User user=userService.getAuthenticationInfo(getToken());
		return _findVoByRole(user.getRole());
	}
	
	/**
	 * 根据角色返回
	 * @param role
	 * @return
	 */
	private List<ManageMenuVo> _findVoByRole(int role)
	{
		return manageMenuDAO.findVoByRole(role);
	}
}